#ifndef COMMUNICATIONS_H
#define COMMUNICATIONS_H
#include "lecture_dossier.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#define SIZE_BUF 10000
#define SIZE_PORT 5
#define SIZE_KEY 32
#define SIZE_LENGTH_FILE 10
#define SIZE_PIECE_SIZE 10
#define SIZE_CRITERION 10
#define SIZE_INDEX 10
#define SIZE_BUFFERMAP 10

#define MAX_TOKEN 10000
#define KO 3

void send_announce(int port, char *dossier_donnees, char *dossier_dl, int taille_piece, FILE * out);
void send_look(char ** criteres, FILE* out);
void send_getfile(char * cle, FILE * out);
void send_interested(char * cle,FILE*out);
void reply_have(struct fichier_partage* fichier,FILE* out);
void send_getpieces(char * cle, int* tab_piece,FILE*out);
void reply_data(struct fichier_partage *fichier,int*tab_piece,FILE*out,char* dossier);
void send_update(char *dossier_donnees, char *dossier_dl, int taille_piece, FILE* out);
void send_pieces(struct fichier_partage * fichier,int piece_nb,FILE*out,char * dossier);
void get_pieces(char* piece,int piece_nb,struct fichier_partage * fichier,char* dossier_dl);

char ** cut_char(char* message);
int read_white(char* out,FILE*in);

int receive_announce(FILE * in);
int receive_look(struct file* resultat_recherche,FILE*in,int taille_piece);
char ** receive_getfile(struct fichier_partage * fichier,FILE*in);
char * receive_interested(FILE * in);
char* receive_have(struct fichier_partage* fichier,FILE*in);
int * receive_getpieces(struct file *,struct fichier_partage ** fichier,FILE * in);
int receive_data(struct fichier_partage * fichier,FILE*in,char* dossier_dl);

int readstart(FILE *in);
#endif

